<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改商品类型')" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goodsLx-edit" th:object="${goodsLx}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
            
            <h4 class="form-header h4">类型详情</h4>    
			<div class="form-group">	
				<label class="col-sm-2 control-label">商品类型名称：</label>
				<div class="col-sm-3">
					<input id="goodsLxName" name="goodsLxName" th:field="*{goodsLxName}" class="form-control" type="text">
				</div>
				
				<label class="col-sm-2 control-label">是否有效：</label>
				<div class="col-sm-3">
					<select id="valid" name="valid" class="form-control m-b" th:field="*{valid}">
							<option value="1">有效</option>
							<option value="0">无效</option>							
					</select>
				</div>
			</div>
			
			<div class="form-group">	
				<label class="col-sm-2 control-label">排序：</label>
				<div class="col-sm-3">
					<input id="line" name="line" th:field="*{line}" class="form-control" type="text">
				</div>
			</div>
			
			<div class="form-group">	
				<label class="col-sm-2 control-label">商品类型图片：</label>				
				<div class="col-sm-8">				
					<input id="imgs" name="imgs" class="form-control" type="hidden" th:field="*{imgs}">
					<img id="imageUrlSrc" width="200px" height="200px" onclick="avator()"/>					
				</div>			
			</div>
			
			<div class="form-group">
				<label class="col-sm-4 control-label"><span style="color: red; ">*点击图片进行图片选择</span></label>				
			</div>
			
			<div class="form-group">
				<div id="preview" style="display: none;">
						<p>
							上传文件： <input id="file" type="file" name="file" />
						</p>
					</div>
			</div>
			
			
			
			<h4 class="form-header h4">改动详情</h4>  
				
			
			<div class="form-group">	
				<label class="col-sm-2 control-label">创建人：</label>
				<div class="col-sm-3">
					<input id="createBy" name="createBy" th:field="*{createBy}" class="form-control" type="text" readonly="readonly">
				</div>
				
				<label class="col-sm-2 control-label">修改人：</label>
				<div class="col-sm-3">
					<input id="modifyBy" name="modifyBy" th:field="*{modifyBy}" class="form-control" type="text" readonly="readonly"> 
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">创建时间：</label>
				<div class="col-sm-3">
					<input id="creactDate" name="creactDate" th:field="*{creactDate}" class="form-control" type="text" readonly="readonly">
				</div>
				
				<label class="col-sm-2 control-label">修改时间：</label>
				<div class="col-sm-3">
					<input id="modifyDate" name="modifyDate" th:field="*{modifyDate}" class="form-control" type="text" readonly="readonly">
				</div>
			</div>
			
		</form>
    </div>
    <div th:include="include::footer"></div>
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
		var prefix = ctx + "GoodsLx/goodsLx";
		$("#form-goodsLx-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-goodsLx-edit').serialize());
	        }
	    }
		
		var preview = document.querySelector('#preview');
		var eleFile = document.querySelector('#file');
		eleFile.addEventListener('change', function() {
			var file = this.files[0];
			// 确认选择的文件是图片                
			if (file.type.indexOf("image") == 0) {
				var reader = new FileReader();
				reader.readAsDataURL(file);
				reader.onload = function(e) {
					// 图片base64化
					var newUrl = this.result;
					//preview.style.backgroundImage = 'url(' + newUrl + ')';
					$("#imageUrlSrc").attr("src", newUrl);
					$("input[name=imgs]").val(newUrl);				
				};
			}
		});
		
		function avator() {
			$("#file").click();
		}
		
		var img = document.getElementById('imageUrlSrc');
		var fileinput = document.getElementById('imgs');
		if (fileinput.value != '') {
			img.src = fileinput.value;
		}
	</script>
</body>
</html>
